package com.tjx.controller;


import com.tjx.common.Result;
import com.tjx.entity.Order;
import com.tjx.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author tjx
 * @since 2025-10-29
 */
@RestController
@RequestMapping("/order")
public class OrderController {
        @Autowired
        IOrderService orderService;
        /**
         * 创建订单
         * @param order 订单对象
         * @return 创建的订单对象
         */
        @PostMapping("/create")
        public Result<Order> createOrder(@RequestBody Order order) {
            return Result.ok("订单创建成功",orderService.createOrder(order));
        }
        /**
         * 查询用户所有订单
         * @param order 订单对象，包含用户ID
         * @return 用户所有订单对象
         */
        @GetMapping("/getByUserId")
        public Result<List<Order>> getOrderByUserId(@RequestBody Order order) {
            return Result.ok("查询用户所有订单成功",orderService.getOrderByUserId(order));
        }


}
